import { defineStore } from "pinia";
import { ref } from "vue";

export const useAuthStore = defineStore("auth", () => {
  const token = ref(localStorage.getItem("token") || null);

  // 设置 token
  const setToken = (newToken) => {
    token.value = newToken;
    localStorage.setItem("token", newToken);
  };

  // 清除 token
  const clearToken = () => {
    token.value = null;
    localStorage.removeItem("token");
  };

  return {
    token,
    setToken,
    clearToken,
  };
});
